package com.gmlive.common.sample.coroutines

import android.os.Bundle
import com.gmlive.common.sample.R
import com.gmlive.common.ui.app.IkCompatActivity
import com.gmlive.common.ui.app.annotation.Immerse
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import kotlinx.android.synthetic.main.activity_coroutines.*

/**
 *
 * @Author sven
 * @Date 2020/6/2
 */
@Immerse(translucentStatus = true, darkStatusBar = true, fitSystemWindows = true)
class CoroutinesActivity : IkCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_coroutines)

        coroutines_button.setOnClickListener {
            val type = object : TypeToken<ApiBaseBean<String>>() {}.type
            val string = """
                {
                    "code":0,
                    "message":"请求成功",
                    "data":"success"
                }
            """.trimIndent()
            val result: ApiBaseBean<String> = Gson().fromJson(string)

            println(result)
        }
    }
}
inline fun <reified T> Gson.fromJson(json: String): T = fromJson(json, T::class.java)

data class ApiBaseBean<T>(
        val code: Int,
        val message: String,
        val data: T?
)
